<template>
	<el-container class="home-container">
		<!-- 头部区域 -->
		<el-header>
			<div>
				<span>权限管理系统</span>
			</div>
			<el-button type="info" @click="loginout">退出</el-button>
		</el-header>
		<!-- 页面主体区域-->
		<el-container>
			<!-- 侧边栏-->
			<el-aside :width="iscoll?'64px':'250px'">
				<div class="togglebtn" @click="toggleapse()">|||</div>
				<!-- 侧边栏菜单区域 -->
				<el-menu background-color="#333744" text-color="#fff" active-text-color="#409EFF" :unique-opened="true"
					:collapse="iscoll" :collapse-transition="false" :router="true" :default-active="activePath">
					<!-- 一级菜单 -->
					<el-submenu width="250px" :index="item.Id +''" v-for="item in menulist" :key="item.Id">
						<!-- 一级菜单的模板 -->
						<template slot="title">
							<!-- 图标 -->
							<i :class="icon[item.Id]"></i>
							<!-- 文本 -->
							<router-link to="/welcome">
								<span>{{item.Name}}</span>
							</router-link>
						</template>
						<!-- 二级菜单 -->
						<template v-for="submin in menulist1">
							<el-menu-item  width="250px" :index="'/'+submin.Path" :key="submin.Id" v-if="submin.ParentId==item.Id"
								@click="SaveStatus('/'+submin.Path)">
								<!-- 图标 -->
								<i class="el-icon-menu"></i>
								<!-- 文本 -->
								<span>{{submin.Name}}</span>
							</el-menu-item>
						</template>
					</el-submenu>
				</el-menu>
			</el-aside>
			<!-- 右侧内容主体 -->
			<el-main>
				<router-view></router-view>
			</el-main>
		</el-container>
	</el-container>
</template>

<script>
	export default {
		data() {
			return {
				menulist: [],
				menulist1: [],
				icon: {
					'1': 'iconfont icon-user',
					'2': 'iconfont icon-tijikongjian',
					'3': 'iconfont icon-shangpin',
					'4': 'iconfont icon-danju',
					'5': 'iconfont icon-baobiao',
					'6': 'iconfont icon-user',
					'7': 'iconfont icon-tijikongjian',
					'10': 'iconfont icon-shangpin',
					'11': 'iconfont icon-danju',
					'12': 'iconfont icon-baobiao'
				},
				iscoll: false,
				//被激活的链接
				activePath: ''
			}
		},
		created() {
			this.getMenuList()
			this.activePath = window.sessionStorage.getItem('activePath')
		},
		methods: {
			loginout() {
				window.sessionStorage.clear();
				this.$router.push('/login');
			},
			//获取所有菜单
			getMenuList() {
				let s = window.sessionStorage.getItem('token');
				console.log(s);
				let _this = this;
				this.$axios.post('/api/api/Home/GetMenuList', {
					Id: parseInt(s)
				}).then(function(res) {
					console.log(res.data.data1);
					console.log(res.data.data2);
					if (res.status == 200) {
						// console.log(res);
						_this.menulist = res.data.data1;
						_this.menulist1 = res.data.data2;
					}
				}).catch(function(res) {
					console.log(res);
				})
			},
			toggleapse() {
				this.iscoll = !this.iscoll
			},
			//保存链接激活状态
			SaveStatus(activePath) {
				window.sessionStorage.setItem('activePath', activePath)
				this.activePath = activePath
			}
		}
	}
</script>

<style>
	div>a {
		background-color: #333744;
		color: #FFFFFF;
		text-decoration: none;
		font-size: 24px;
	}

	.router-link-active {
		text-decoration: none;
		background-color: #333744;
	}

	.home-container {
		height: 100%;
	}

	.el-header {
		background-color: #373d41;
		display: flex;
		justify-content: space-between;
		padding-left: 0px;
		align-items: center;
		color: #fff;
		font-size: 20px;

		>div {
			display: flex;
			align-items: center;

			img {
				width: 50px;
				height: 50px;
			}

			span {
				margin-left: 15px;
			}
		}
	}

	.el-aside {
		background-color: #333744;

		.el-menu {
			border-right: none;
		}
	}

	.el-main {
		background-color: #eaedf1;
	}

	.iconfont {
		margin-right: 10px;
	}

	.togglebtn {
		background-color: #4a5064;
		font-size: 10px;
		line-height: 24px;
		color: #fff;
		text-align: center;
		letter-spacing: 0.2em;
		cursor: pointer;
	}
</style>
